package com.max.socket.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashSet;
import java.util.Set;

public class ChatSocketServer {

    private final static Set<Socket> clients = new HashSet<>();

    public static void main(String[] args) {
        try (ServerSocket serverSocket = new ServerSocket(8080)) {
            System.out.println("服务器启动成功......");
            while (true) {
                System.out.println("等待客户端链接....");
                Socket accept = serverSocket.accept();
                System.out.println("获取到客户端链接....");
                //获取到客户端链接之后维护连接并处理
                /*ServerClientThread socketThread = new ServerClientThread(accept, clients);
                new Thread(socketThread).start();*/
                new ServerClientThread(accept, clients).start();
                clients.add(accept);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


}
